﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IMedicare
{
    public class IMedicareFactory
    {
        /// <summary>
        /// IMedicareFactory
        /// </summary>
        private IMedicareFactory()
        {

        }
        private static IMedicareFactory iMedicareFactory = new IMedicareFactory();
        public static IMedicareFactory Instance
        {
            get
            {
                return iMedicareFactory;
            }
        }

        private static IMedicare iMedicare;
        public IMedicare CreateIMedicare()
        {
            if (iMedicare == null)
            {
                iMedicare = new SDRZDRInterface();
            }


            return iMedicare;
        }

        private static object objectT;
        public T CreateInterface<T>() where T : class, new()
        {

            if (objectT == null)
            {
                objectT = new T();
            }


            return objectT as T;
        }

        /// <summary>
        /// 创建实例
        /// </summary>
        /// <typeparam name="T">指定要创建的实例类型</typeparam>
        /// <param name="initial">初始化实例</param>
        /// <returns>实例</returns>
        public static T Create<T>(Action<T> initial)
            where T : new()
        {
            T t = new T();
            if (initial != null)
            {
                initial(t);
            }
            return t;
        }
    }

}
